﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace McMySkin_Installer
{
    public partial class NewMainForm : Form
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);

        const int CS_DropSHADOW = 0x20000;
        const int GCL_STYLE = (-26);

        [DllImport("User32.dll", EntryPoint = "SendMessage")]
        private static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
        [DllImport("User32.dll", EntryPoint = "ReleaseCapture")]
        private static extern int ReleaseCapture();

        public NewMainForm()
        {
            CheckForIllegalCrossThreadCalls = false;
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
            InitializeComponent();
        }

        public void UpdateLoginStatus()
        {
            if (LoginStatus.Login)
            {
                label2.Text = "您好，" + LoginStatus.NickName + " ！" ;
            }

            button2.Enabled = LoginStatus.Login;

            pictureBox9.BackgroundImage = Image.FromStream(Unit.GetPiutureStream("http://www.mcmyskin.com/members/index.php?uid="+ LoginStatus.Uid + "&size=50&r12552"));
        }

        private void NewMainForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(this.Handle.ToInt32(), 0x0112, 0xF012, 0);
            }
        }

        private void NewMainForm_Load(object sender, EventArgs e)
        {
            
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.BackgroundImage = global::McMySkin_Installer.Properties.Resources.closeOnMouse;
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.BackgroundImage = global::McMySkin_Installer.Properties.Resources.close;
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            new RestoreForm().ShowDialog();
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            new SettingForm().ShowDialog();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            new InstallForm().ShowDialog();
        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {
            new AboutForm().ShowDialog();
        }

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(this.Handle.ToInt32(), 0x0112, 0xF012, 0);
            }
        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            new LoginForm(this).ShowDialog();
        }
    }
}
